package com.example.app.utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class SqliteHelper extends SQLiteOpenHelper {
    private static final int VERSION=4;//版本
    public static final String DB_NAME = "liandatabase.db";//数据库名字


    public SqliteHelper(Context context) {
        super(context, DB_NAME, null, VERSION);
        Log.d("数据库", "成功启动");
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        try{
            db.execSQL("create table if not exists staff(_id integer primary key autoincrement,pnumber varchar(20)," +
                    "pname varchar(20),psex varchar(5),page integer,job varchar(20),pdepartment varchar(50),salary varchar(20),phone varchar(11))");
            db.execSQL("create table if not exists department(_id integer primary key autoincrement,departmentID varchar(20),departmentName varchar(50),principal varchar(20),tel varchar(11),personNum integer)");
            Log.i("数据库表", "创建成功！");
        }
        catch(Exception e){
            Log.i("数据库表", "创建失败！");
            Log.i("数据库表", e.getMessage());
        }
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Create tables again
        db.execSQL("DROP TABLE IF EXISTS staff");
        db.execSQL("DROP TABLE IF EXISTS department");
        onCreate(db);
    }
}
